﻿import QtQuick 2.12
import QtQuick.Controls 2.15

Button {
    id: _root
    opacity: 0.6
    property string imageSource
    property color  backgroundColorHighlight: _backgroundColorHighlight
    property color backgroundColor: _backgroundColor

    readonly property color  _backgroundColorHighlight: uiPref.buttonColorHighlight
    readonly property color _backgroundColor: "white"
    property bool   _showHighlight:     pressed | hovered | checked

    UiPref { id: uiPref }

    function setButtonChecked(checked) {
        if (checked) {
            _root.backgroundColor = "#00FF00"
        } else {
            _root.backgroundColor = _backgroundColor
        }
    }

    contentItem: Item {
        Image {
            id: buttonImage
            source: imageSource
            anchors.centerIn: parent
            width: parent.width * 1.2
            height: parent.height * 1.2
            fillMode: Image.PreserveAspectFit
        }
    }

    background: Rectangle {
        color: _showHighlight ? backgroundColorHighlight : backgroundColor
        border.color: "gray"
        border.width: 1
        radius: 0
    }
}

